package com.mybatis.demo;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.mybatis.demo.mapper.NodeMapper;
import com.mybatis.demo.po.Node;
import com.mybatis.demo.po.NodePageQuery;

public class MainPage {

    public static void main(String[] args) {
        String resource = "mybatis-config-page.xml";
        InputStream inputStream=null;
        try {
        	// 全局配置文件输入流
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // 连接工厂
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = null;
        try {
        	// 一个连接
            sqlSession = sqlSessionFactory.openSession();
            NodeMapper roleMapper = sqlSession.getMapper(NodeMapper.class);

            NodePageQuery query = new NodePageQuery();
            query.setPageSize(5);
            query.setFull(true);
            System.out.println(roleMapper.getNodePageable(query));

            sqlSession.close();

        } catch (Exception e) {
            // TODO Auto-generated catch block
            sqlSession.rollback();
            e.printStackTrace();
        }finally {
            sqlSession.close();
        }
    }
}
